package com.itqf.controller;

import com.itqf.entity.SysMenu;
import com.itqf.service.SysMenuService;
import com.itqf.utils.R;
import com.itqf.utils.ResultData;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 徐老板
 * @date 2020/1/25   21:51
 */
@RestController
public class SysMenuController {
    @Resource
    private SysMenuService sysMenuService;


///sys/menu/list?order=asc&limit=10&offset=0
//    @RequiresPermissions("sys:menu:list")
    @RequestMapping("/sys/menu/list")
    private ResultData menuList(@RequestParam(value = "limit",required = false) Integer limit,@RequestParam(value = "offset",required = false)Integer offset,
                                @RequestParam(value = "search",required = false)String search,
                                @RequestParam(value = "sort",required = false)String sort,@RequestParam(value = "order",required = false)String order){
        ResultData byPage = sysMenuService.findByPage(limit,offset,search,sort,order);
        System.out.println("menucontroller:"+byPage);
        return byPage;
    }

//    @RequiresPermissions("sys:menu:delete")
    @RequestMapping("/sys/menu/del")
    private R delList(@RequestBody List<Long> ids){
        return sysMenuService.delList(ids);
    }

//    @RequiresPermissions("sys:menu:select")
    @RequestMapping("/sys/menu/select")
    private R selectMenu(){
        return sysMenuService.selectMenu();
    }

    //新增操作
//    @RequiresPermissions("sys:menu:save")
    @RequestMapping("/sys/menu/save")
    private R menuSave(@RequestBody SysMenu sysMenu){
        return sysMenuService.menuSave(sysMenu);
    }



    /**
     *restful风格获取数据
     */
//    @RequiresPermissions("sys:menu:info")
    @RequestMapping("sys/menu/info/{menuId}")
    private R findMenu(@PathVariable int menuId){
        return sysMenuService.menuFind(menuId);
    }

//    @RequiresPermissions("sys:menu:update")
    @RequestMapping("sys/menu/update")
    private R menuUpdate(@RequestBody SysMenu sysMenu){
        return sysMenuService.menuUpdate(sysMenu);
    }

    @RequestMapping("sys/menu/user")
    private R getMenu(){
        R userMenu = sysMenuService.findUserMenu();
        return userMenu;

    }


}
